//
//  BsBottomWithColletionTableViewCell.m
//  Demo
//
//  Created by colawh on 2019/3/16.
//  Copyright © 2019年 colawhdfws. All rights reserved.
//

#import "BsBottomWithColletionTableViewCell.h"
#import "BsBlueCollectionView.h"

@interface BsBottomWithColletionTableViewCell ()

@property (nonatomic,strong) BsBlueCollectionView *colletionView;

@property (nonatomic,strong) UIButton *btn;


@end


@implementation BsBottomWithColletionTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configUI];
    }
    return self;
}
- (void)configUI{
    
    [self.bottomView addSubview:self.colletionView];
    [self.bottomView addSubview:self.btn];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (self.refreshBlock) {
            self.refreshBlock();
        }
    });
  
}
- (void)configureUIWithArray:(NSArray *)array
{
    self.colletionView.dataSource = [array mutableCopy];
    self.colletionView.tag = self.tag;
    
}
- (CGFloat)realHeight{

    if (_btn.selected) {
        return 50+50+[_colletionView realHeight];
    }else{
//        自定义默认高度
        return 50+50+40;
    }
}
- (void)cliclAction{
//    NSLog(@"%@",@(_btn.selected));
//    _btn.selected = !_btn.selected;
    NSLog(@"%@",@(_btn.selected));
    if (_clickBlock) {
        if (_btn.selected) {
            _btn.selected = NO;
        }else{
            _btn.selected = YES;
        }
        _clickBlock();
    }
 
}


- (void)layoutSubviews{
    [super layoutSubviews];
    [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(kUIScreenWidth, 50));
        make.bottom.equalTo(self.bottomView);
        make.top.equalTo(_colletionView.mas_bottom);
    }];
    [_colletionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 50, 0));
    }];
}
- (BsBlueCollectionView *)colletionView{
    if (!_colletionView) {
        _colletionView = [[BsBlueCollectionView alloc]initWithItemArray:@[@"高级酒店管理",@"酒店前台",@"酒店新人超级前台课程",@"酒店新手",@"酒店打工哈根数据啊工商局和按时开酒吧肯定会给",@"高级酒店管理",@"酒店前台",@"酒店新人超级前台课程",@"酒店新手",@"酒店打工哈根数据啊工商局和按时开酒吧肯定会给",@"高级酒店管理",@"酒店前台",@"酒店新人超级前台课程",@"酒店新手",@"酒店打工哈根数据啊工商局和按时开酒吧肯定会给",@"高级酒店管理",@"酒店前台",@"酒店新人超级前台课程",@"酒店新手",@"酒店打工哈根数据啊工商局和按时开酒吧肯定会给",@"高级酒店管理",@"酒店前台",@"酒店新人超级前台课程",@"酒店新手",@"酒店打工哈根数据啊工商局和按时开酒吧肯定会给",@"高级酒店管理",@"酒店前台",@"酒店新人超级前台课程",@"酒店新手",@"酒店打工哈根数据啊工商局和按时开酒吧肯定会给",@"高级酒店管理",@"酒店前台",@"酒店新人超级前台课程",@"酒店新手",@"酒店打工哈根数据啊工商局和按时开酒吧肯定会给"]];
    }
    return _colletionView;
}
- (UIButton *)btn{
    if (!_btn) {
        _btn = [[UIButton alloc]init];
        [_btn setTitle:@"查看更多" forState:UIControlStateNormal];
        [_btn setTitle:@"收回" forState:UIControlStateSelected];
        [_btn addTarget:self action:@selector(cliclAction) forControlEvents:UIControlEventTouchUpInside];
        [_btn setTitleColor:kUIColorFromRGB(0x091522) forState:UIControlStateNormal];
        _btn.titleLabel.font = [UIFont systemFontOfSize:12.0];
    }
    return _btn;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
